<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>测试游戏进入</title>
</head>
<body>
	<input type="text" id="nick_name" placeholder="昵称">
	<button id="root_room">进入房间</button>

  <input type="text" id="text" placeholder="答案">
  <button id="answer">回答</button>
</body>
<script src="https://cdn.bootcss.com/jquery/2.0.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.dev.js"></script>

<script>
const socket = io('http://localhost:3000');
var is_in = false;
socket.on('connect', () => {
  	console.log(socket.id);

  	$("#root_room").click(function(){
  		let userInfo = {"id":2,"nick_name":"老鼠","head_img":"https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83eqT5vA8Fp5YmtIt90icfW0WgbiaRJKQKEzYpQBobEDiaWCekvNGFc1wE7EiaudCL5sYVL2ACbSxcSiaomQ/132","openid":"orK5J5DI3X3OCyV3tTalZKvVHyv3","unionid":"","gender":2,"level":0,"ex":0,"last_time":1526614175,"subtime":1526540306,"login_num":61,"play_num":1,"type":["fast"]};
  		userInfo.nick_name = $("#nick_name").val()?$("#nick_name").val():"老鼠";
      if(!is_in){
        socket.emit("root_room",JSON.stringify(userInfo));
        alert("加入了");
      }
      is_in = true;
  		
  	});

    $("#answer").click(function(){
        let data = $("#text").val();
        socket.emit("answer",data);
        $("#text").val("");
    });
});

socket.on("afterLogin",(res)=>{
    console.log(res);
});

//其他人正在选择是否答题
socket.on("ortherTurn",(res)=>{
  console.log(res);
});

socket.on("status",(res)=>{
  //console.log(res);
});

socket.on("skip_game",res=>{
  console.log(res.nick_name+"选择跳过");
});

socket.on("addCore",res=>{
  console.log("给"+res.userInfo.nick_name+"加"+res.num+"分");
});



//公布答案
socket.on("say_answer",res=>{
  console.log("系统公布答案",res);
});



</script>

</html>